//
//  NavBar.m
//  gameInfo
//
//  Created by lijiangang on 14-1-22.
//  Copyright (c) 2014年 lijiangang. All rights reserved.
//

#import "NavBar.h"

@implementation NavBar

//- (id)initWithFrame:(CGRect)frame
//{
//}
-(id)initWithIsBackImage:(BOOL)have
{
    self = [super init];
    if (self) {
        
        
        self.backgroundColor  = [UIColor clearColor];
        
        // Initialization code
        if (SystemIsiOS7()) {
            self.frame = CGRectMake(0, 0, 320, 64);
            UIImageView *image = [[UIImageView alloc]initWithFrame:self.frame];
            // image.alpha = 0.9;
            image.image = [UIImage imageNamed:@"toubu.png"];
            [self addSubview:image];
        }
        
        
        else
        {
            self.frame = CGRectMake(0, 0, 320, 44);
            UIImageView *image = [[UIImageView alloc]initWithFrame:self.frame];
            // image.alpha = 0.9;
            image.image = [UIImage imageNamed:@"ios6toubu.png"];
            [self addSubview:image];
        }
        
        [self loadView:have];
    }
    return self;

}
- (void)ios6btnTouched:(id)sender {
    [SVProgressHUD dismiss];

    [self.NavDelegate leftBtnTouched:sender];

}

-(void)morebtnTouched:(id)sender
{
    [SVProgressHUD dismiss];

    [self.NavDelegate rightBtnTouched:sender];
}


-(void)loadView:(BOOL)is
{
    self.rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.backImage = [[UIImageView alloc]init];
    if (SystemIsiOS7()) {
        
        if (!is) {
            self.leftBtn.frame = CGRectMake(15, 20,50, 44);

        }
        else
        {
            self.leftBtn.frame = CGRectMake(0, 20,50, 44);
            self.backImage.hidden = YES;

        }
        
        self.rightBtn.frame = CGRectMake(270, 20, 50, 44);
        self.titleLabel  = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 150, 30)];
        self.titleLabel.center = self.center;
        CGRect rect = self.titleLabel.frame;
        rect.origin.y+=10;
        self.titleLabel.frame = rect;
        self.backImage.frame = CGRectMake(0, 32, 20, 20);
        self.backImage.image = [UIImage imageNamed:@"fanhui.png"];
    }
    else
    {
        
        
        if (!is) {
            self.leftBtn.frame = CGRectMake(15, 0,50, 44);
            
        }
        else
        {
            self.leftBtn.frame = CGRectMake(0, 0,50, 44);
            self.backImage.hidden = YES;
            
        }

        
        self.backImage.frame = CGRectMake(0, 11, 20, 20);
        self.backImage.image = [UIImage imageNamed:@"fanhui.png"];

       // self.leftBtn.frame = CGRectMake(0, 0,50, 44);
        self.rightBtn.frame = CGRectMake(270, 0, 50, 44);

        self.titleLabel  = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 150, 30)];
        
        self.titleLabel.center = self.center;
     //   CGRect rect = self.titleLabel.frame;
      //  rect.origin.y＋;
    }
    
      //  self.backBtn.backgroundColor = [UIColor redColor];
   // [self.backBtn setTitle:@"<" forState:UIControlStateNormal];
  //  [self.backBtn setImage:[UIImage imageNamed:@"icon_back_bar.png"] forState:UIControlStateNormal];
  //  [self.backBtn setTitle:@"返回" forState:UIControlStateNormal];
    [self.leftBtn setTitleColor:ColorRGB(0, 122, 255) forState:UIControlStateNormal];
        [self.leftBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    [self addSubview:self.leftBtn];
    [self.rightBtn setTitleColor:ColorRGB(0, 122, 255) forState:UIControlStateNormal];
    [self.rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    
    [self addSubview:self.rightBtn];
        [self.rightBtn addTarget:self action:@selector(morebtnTouched:) forControlEvents:UIControlEventTouchUpInside];
    [self.leftBtn addTarget:self action:@selector(ios6btnTouched:) forControlEvents:UIControlEventTouchUpInside];
   // self.title.text = self.title;
    self.titleLabel.backgroundColor = [UIColor clearColor];
    self.titleLabel.textColor = [UIColor blackColor];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.font = [UIFont boldSystemFontOfSize:20];
    [self addSubview:self.titleLabel];
     [self addSubview:self.backImage];
    
    UIImageView *backimage = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5, 20, 20)];
    [self addSubview:backimage];
   }
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
